#include<cstdio>
#include<string>
using namespace std;
int main()
{
    fin=fopen("test.kk","rb");
    fout=fopen("out.txt","wb");
    plen=&len;
    while(0!=(fread(plen,sizeof(short),1,fin)))
    {
        printf("%d\n",len);
        if(len==0)
        {
            fread(pin,1,1,fin);
            pa=&a;pb=&b;
            fread(pa,sizeof(short),1,fin);
            fread(pb,sizeof(char),1,fin);
            while(a==0&&b==0);
            {
                if(b==0)
                {
                    a--;
                    b=255;
                }
                fwrite(pin,1,1,fin);
                b--;
            }
        }
        else
        {
            for(i=1;i<=len;i++)
            {
                fread(pin,1,1,fin);
                fwrite(pin,1,1,fin);
            }
        }
    }
    fclose(fin);
    fclose(fout);
}
